﻿
var takeSee = {};
takeSee.beginSearch = function () {
    if ($('#txtInquiryFollowSearchValue').attr('noChecked')) {
        $('#txtInquiryFollowSearchValue').css('color', 'red');
        return false;
    }
    window.commonPageStartTime = new Date();
    //此方法在分页控件中
    if ("undefined" != typeof ajaxpageronbegin) {
        ajaxpageronbegin();
    }
    other.showLoaderMask();
};
takeSee.changeDate = function () {
    var temf = $("#txtDateTimeStart").val();
    var temt = $("#txtDateTimeEnd").val();
    if (temf != "" && temt != "") {
        if (timehelper.parseDate(temf) > timehelper.parseDate(temt)) {
            $("#txtDateTimeEnd").val(temf);
            $("#txtDateTimeStart").val(temt);
        }
    }
};
takeSee.pageOnSuccessFun = function () {
    if ('undefined' != typeof timehelper) {
        $("#timeCount").html("查询耗时" + timehelper.TimeDiffirence(window.commonPageStartTime, new Date()).msDiff + "毫秒");
    }
    if ($("#hidTakeSeeCount").length > 0 && $("#spanInquiryCount").length > 0) {
        var temarray = $("#hidTakeSeeCount").val().split(',');
        $("#spanInquiryCount").html(temarray[0]);
        $("#spanTakeSeeGroupCount").html(temarray[2]);
        $("#spanTakeSeeCount").html(temarray[1]);
    }
    other.hideLoaderMask();
};
takeSee.SeeInfo = function (e) {
    var keyid = $(e).attr("keyid");
    $.dialog({
        id: "dialogContact",
        width: 635,
        heigth: 128,
        lock: true,
        title: "客户带看",
        content: $("#popTakeSee").html()
    });
    $.ajax({
        type: 'post',
        url: '/customer/inquiry-take-see-info',
        data: {
            'keyid': keyid
        },
        success: function (data) {
            $("#takeseeinfodiv").html(data);
            $("#takeseeload").hide();
        }
    });
};

takeSee.SelectProperty = function (e) {
    var temtag;
    var $selectedHouseTypes = $("#propertyType :checked[name=chbpropertyType]");
    var houseTypesArray = [];
    $("#txtEstateNames").val() || $("#txtBuildingNames").val() || $("#txtHouseNo").val() || $("#txtFloor").val() || $selectedHouseTypes.length > 0 || (temtag = 1);
    if (temtag) {
        $.OKDialogAgency('<div class="tc">请至少提供一项搜索条件！</div>');
        return;
    }
    if ($selectedHouseTypes.length > 0) {
        $selectedHouseTypes.each(function () {
            houseTypesArray.push($(this).val());
        });
    }
    var url = "/customer/property-only-list-find";
    if ($("#selectSource").find("#btnCheckdown").attr("showAndHid") == "1") {
        url += "?single=1";
    }
    var reqData = {
        "EstateNames": $("#txtEstateNames").val(),
        "BuildingNames": $("#txtBuildingNames").val(),
        "HouseNo": $("#txtHouseNo").val(),
        "Floor": $("#txtFloor").val(),
        "HouseTypes": houseTypesArray.join(",")
    };
    $.AjaxAgency(url, reqData, function (data) {
        $("#selectPropertydiv").html(data);
    });
    //删除房型下拉框
    $("#propertyType").hide();
};
takeSee.SelectCustomer = function (e) {
    if (!$("#txtStringkey").val()) {
        $("#stringkeyerror").show();
        return;
    } else {
        $("#stringkeyerror").hide();
    }
    $.ajax({
        type: 'post',
        url: '/customer/inquiry-for-filter-find',
        data: {
            'SelectType': $("#cmbSelectType").val(),
            'Stringkey': $("#txtStringkey").val()
        },
        success: function (data) {
            $("#selectCustomerdiv").html(data);
        }
    });
};
takeSee.selectedCustomer = function (e) {
    var keyid = $(e).attr("keyid");
    var customerName = $(e).attr("customerName");
    var customerNameSpan = $("#customerNameSpan");
    customerNameSpan.attr("keyid", keyid);
    customerNameSpan.attr("customerNo", $(e).attr("customerNo"));
    customerNameSpan.html(customerName);
    art.dialog({ id: "selectCustomer" }).close();

};
takeSee.selectedProperty = function (e) {
    $("#propertytable").find("input[name=selectProperty]:checked").each(function (i, e) {
        var currentel = $(this);
        var trustTypeCode = currentel.attr("TrustTypeCode");
        var temp = "<div style='margin-left:25px;' class='info-list' pn='" + currentel.attr("PropertyNo") + "' Square='" + currentel.attr("Square") + "' roomtype='" + currentel.attr("countF") + "室" + currentel.attr("countT") + "厅' keyid='" + currentel.attr("keyid") + "'><span name='PropertyInfo' title='" + currentel.attr("PropertyInfo") + "' style='display:inline-block;width:152px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:middle;'>" + currentel.attr("PropertyInfo") + "</span>";
        temp += "    <strong class='ml0'>约看类型：</strong>";
        switch (trustTypeCode) {
            case "10":
                temp += "      <select class='select ReserveSeePropertyType' style='width:54px;'>";
                temp += "         <option value='10' selected='selected'>看租</option>";
                temp += "      </select>";
                temp += "      <span class='ReserveRentPrice' style='display:inline-block;width:90px;vertical-align:middle;'><strong class='ml0'>租价：</strong>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
                break;
            case "20":
                temp += "      <select class='select ReserveSeePropertyType' style='width:54px;'>";
                temp += "         <option value='20' selected='selected'>看售</option>";
                temp += "      </select>";
                temp += "      <span class='ReserveSalePrice' style='display:inline-block;width:90px;'><strong class='ml0'>售价：</strong>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
                break;
            default:
                temp += "      <select class='select ReserveSeePropertyType' style='width:54px;'>";
                temp += "         <option value='20' selected='selected'>看售</option>";
                temp += "         <option value='10'>看租</option>";
                temp += "      </select>";
                temp += "      <span class='ReserveSalePrice' style='display:inline-block;width:90px;'><strong class='ml0'>售价：</strong>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
                temp += "      <span class='ReserveRentPrice' style='display: none;'><strong>租价：</strong>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
                break;
        }
        temp += "      <strong class='ml0'><em class='red'>*</em>约看时间：</strong>";
        temp += "       <input type='text' class='ipt w69' name='reserveTime' onclick='WdatePicker({dateFmt:\"yyyy-MM-dd\",minDate:\"%y-%M-%d\", readOnly: true})' />";
        temp += "       <select class='select' name='hour' style='width:44px;'><option value='00'>00</option><option value='01'>01</option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='05'>05</option><option value='06'>06</option><option value='07'>07</option><option value='08'>08</option><option value='09'>09</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option></select>";
        temp += "       <select class='select' name='minute' style='width:44px;'><option value='00'>00</option><option value='10'>10</option><option value='15'>15</option><option value='30'>30</option><option value='45'>45</option></select>";
        temp += "        <span><i class='delinfo' onclick='takeSee.delline(this)' title='删除房源'></i></span></div>";
        var temresult = true;
        $("#reserveListdiv").find(".info-list").each(function () {
            if ($(this).attr("keyid") == currentel.attr("keyid")) {
                temresult = false;
            }
        });
        if (temresult) {
            $("#reserveListdiv").append(temp).css("margin-bottom", "10px");
        }
    });

    $(".ReserveSeePropertyType").unbind("change").bind("change", function () {
        if ($(this).val() == "20") {
            $(this).nextAll(".ReserveSalePrice").show();
            $(this).nextAll(".ReserveRentPrice").hide();
        } else if ($(this).val() == "10") {
            $(this).nextAll(".ReserveSalePrice").hide();
            $(this).nextAll(".ReserveRentPrice").show();
        }
    });

    art.dialog({ id: "selectSource" }).close();
};
takeSee.delline = function (e) {
    $(e).parent().parent().remove();
};
takeSee.saveAndContinueReserves = function (e) {
    if (!$("#customerNameSpan").html()) {
        $.OKDialogAgency('<div class="tc">请选择客源！</div>');
        return;
    }
    if (!$("#reserveListdiv").html()) {
        $.OKDialogAgency('<div class="tc">请选择约看的房源！</div>');
        return;
    }
    var timecheck = true;
    $("input[name=reserveTime]").each(function () {
        this.value || (timecheck = false);
    });
    if (!timecheck) {
        $.OKDialogAgency('<div class="tc">有房源约看时间没填！</div>');
        return;
    }
    var customerNameSpan = $("#customerNameSpan");
    $("#reserveListdiv").find(".info-list").each(function () {
        var temtr = "<tr><td>" + customerNameSpan.attr("customerNo") + "</td>";
        temtr += "<td>" + customerNameSpan.html() + "</td>";
        temtr += "<td>" + $(this).find("option:selected").text() + "</td>";
        temtr += "<td>" + $(this).find("input").val() + "</td>";
        temtr += "<td>" + $(this).attr("pn") + "</td>";
        temtr += "<td>" + $(this).find("span[name=PropertyInfo]").html() + "</td>";
        temtr += "<td>" + $(this).attr("roomtype") + "</td>";
        temtr += "<td>" + $(this).attr("Square") + "</td>";
        temtr += "<td>" + $(this).find("span[name=saleprice]").html() + "/" + $(this).find("span[name=RentPrice]").html() + "</td>";
        temtr += "<td><input name='reserveinfo' seetype='" + $(this).find("select").val() + "' time='" + $(this).find("input").val() + "' pkeyid='" + $(this).attr("keyid") + "' customerkeyid='" + customerNameSpan.attr("keyid") + "' type='hidden'  /><a class='cpt' onclick='takeSee.delline(this)'>删除</a></td></tr>";
        var temtable = $("#reserveList").append(temtr);
        temtable.find("input:last").val($("#hidcontent").val());
    });

    art.dialog({ id: 'inputGuide' }).close();
};
takeSee.saveReservesCheck = function (e) {
    if (!$("#customerNameSpan").html()) {
        $.OKDialogAgency('<div class="tc">请选择客源！</div>');
        return;
    }
    if (!$("#reserveListdiv").html()) {
        $.OKDialogAgency('<div class="tc">请选择房源！</div>');
        return;
    }
    var timecheck = true;
    $("input[name=reserveTime]").each(function () {
        this.value || (timecheck = false);
    });
    if (!timecheck) {
        $.OKDialogAgency('<div class="tc">有房源约看时间没填！</div>');
        return;
    }

    $.dialog({
        id: "saveInputInvite",
        lock: true,
        content: $("#saveInputInvite").html()
    });
};
takeSee.saveReservesCheck2 = function (e) {
    $("#saveReservesCheck2").attr("disabled", "disabled");
    if (!$("#reserveListdiv").html()) {
        $.OKDialogAgency('<div class="tc">请选择房源！</div>');
        $("#saveReservesCheck2").removeAttr("disabled");
        return;
    }
    var timecheck = true;
    $("input[name=reserveTime]").each(function () {
        this.value || (timecheck = false);
    });
    if (!timecheck) {
        $.OKDialogAgency('<div class="tc">有房源约看时间没填！</div>');
        $("#saveReservesCheck2").removeAttr("disabled");
        return;
    }
    if ($.trim($("#hidcontent").val()) == "") {
        $("#contenterror").show();
        $("#saveReservesCheck2").removeAttr("disabled");
        return;
    }
    $.dialog({
        id: "saveInputInvite",
        lock: true,
        content: $("#saveInputInvite").html(),
        close: function () {
            $('#saveReservesCheck2').removeAttr('disabled');
        }
    });
};
takeSee.clearInput = function () {
    $("#writeFollow").find("input[type=text]").each(function () {
        $(this).val("");
    });
    $("#writeFollow").find("textarea").each(function () {
        $(this).val("");
    });
};
takeSee.saveReservesDirect = function (e) {
    $("#saveReservesDirect").attr("disabled", "disabled");
    var items = [], tempFollowTypeKeyId = '', tempFollowTypeCode = '';
    var customerNameSpan = $("#customerNameSpan");
    var msgtime = $("#txtMsgTime").val();

    //提醒Ta
    var contactsKeyIds = [], customerOrDeptNames = [], contactsDepartKeyIds = [];
    var content = $("#hidcontent").val();
    if (!!$("#spanAddContacts") && $("#spanAddContacts").find("span").length > 0) {
        $("#spanAddContacts").find("span").each(function () {
            var contactsKeyId = $(this).find("[name=contactsKeyId]").val();
            var contactsName = $(this).find("[name=contactsName]").val();

            var contactsDepKeyId = $(this).find("[name=contactsDepKeyId]").val();

            var contactsDepartKeyId = $(this).find("[name=contactsDepartKeyId]").val();
            var contactsDepartName = $(this).find("[name=contactsDepartName]").val();
            if (contactsKeyId) {
                contactsKeyIds.push(contactsKeyId);
            }
            if (contactsName) {
                customerOrDeptNames.push(contactsName);
            }
            if (contactsDepartKeyId) {
                contactsDepartKeyIds.push(contactsDepartKeyId);
            }


            if (contactsDepartName) {
                customerOrDeptNames.push(contactsDepartName);
            }
        });
    }
    if (customerOrDeptNames.length > 0) {
        content = $("#hidcontent").val() + ";提示Ta:" + customerOrDeptNames.join(",");
    }

    $("#reserveListdiv").find(".info-list").each(function () {
        var item = {};
        item.InquiryKeyId = customerNameSpan.attr("keyid");
        item.SeePropertyType = $(this).find("select").val();
        item.ReserveTime = $(this).find("input").val() + " " + $(this).find("[name=hour]").val() + ":" + $(this).find("[name=minute]").val() + ":00";
        for (var i = 0; i < SysParam.length; i++) {
            if (SysParam[i].ParameterType == 60) {
                for (var j = 0; j < SysParam[i].Items.length; j++) {
                    if (SysParam[i].Items[j].ItemCode == '100') {
                        tempFollowTypeKeyId = SysParam[i].Items[j].ItemValue;
                        tempFollowTypeCode = '100';
                    }
                }
            }
        }
        ;
        item.FollowTypeCode = tempFollowTypeCode;
        item.FollowTypeKeyId = tempFollowTypeKeyId;
        item.PropertyKeyId = $(this).attr("keyid");
        item.Content = content;
        item.MsgUserKeyIds = contactsKeyIds;
        item.MsgDeptKeyIds = contactsDepartKeyIds;

        item.MsgTime = msgtime;
        items.push(item);
    });
    $.AjaxAgency("inquiry-follow-add-ajax", JSON.stringify(items), function (data) {
        if (data != "ok") {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
        } else {
            if (window.location.href.indexOf("inquiry-detail-follow") > -1) {
                $("#searchForm").submit();
                art.dialog({ id: "saveInputInvite" }).close();
                window.location = window.location;
                takeSee.clearInput();
                $("#spanAddContacts").empty();
            } else {
                window.location = window.location;
            }
        }
    });
    $("#saveReservesCheck2").removeAttr("disabled");
};

takeSee.addTakeSee = function (e) {
    $("#addTakeSee").attr("disabled", "disabled");
    var msgtime = $("#txtMsgTime1").val();

    //提醒Ta
    var contactsKeyIds = [], customerOrDeptNames = [], contactsDepartKeyIds = [];
    var content = $("#txtContent").val();
    if (!!$("#spanAddContacts2") && $("#spanAddContacts2").find("span").length > 0) {
        $("#spanAddContacts2").find("span").each(function () {
            var contactsKeyId = $(this).find("[name=contactsKeyId]").val();
            var contactsName = $(this).find("[name=contactsName]").val();

            var contactsDepKeyId = $(this).find("[name=contactsDepKeyId]").val();
            var contactsDepartKeyId = $(this).find("[name=contactsDepartKeyId]").val();
            var contactsDepartName = $(this).find("[name=contactsDepartName]").val();
            if (contactsKeyId) {
                contactsKeyIds.push(contactsKeyId);
            }
            if (contactsName) {
                customerOrDeptNames.push(contactsName);
            }


            if (contactsDepartKeyId) {
                contactsDepartKeyIds.push(contactsDepartKeyId);
            }
            if (contactsDepartName) {
                customerOrDeptNames.push(contactsDepartName);
            }
        });
    }
    if (customerOrDeptNames.length > 0) {
        content = $("#txtContent").val() + ";提示Ta:" + customerOrDeptNames.join(",");
    }

    var item = {}, tempFollowTypeKeyId = '', tempFollowTypeCode = '';
    item.InquiryKeyId = $("#hidckid").val();
    for (var i = 0; i < SysParam.length; i++) {
        if (SysParam[i].ParameterType == 60) {
            for (var j = 0; j < SysParam[i].Items.length; j++) {
                if (SysParam[i].Items[j].ItemCode == '110') {
                    tempFollowTypeKeyId = SysParam[i].Items[j].ItemValue;
                    tempFollowTypeCode = '110';
                }
            }
        }
    }
    ;
    item.FollowTypeCode = tempFollowTypeCode;
    item.FollowTypeKeyId = tempFollowTypeKeyId;
    item.AgreementNo = $("#txtAgreementNo").val();
    item.ContentNext = $("#txtContentNext").val();
    item.RentPrice = $("#txtRentPrice").val();
    item.SalePrice = $("#txtSalePrice").val();
    item.LookWithKeyId = $("#hidUserId").val();
    item.SeePropertyType = $("#cmbSeePropertyType").val();
    item.TakeSeeTime = $("#laberTakeTimeDay").html() + " " + $("#cmbTakeTimeHour").val() + ":" + $("#cmbTakeTimeMinute").val() + ":00";
    item.ReserveKeyId = $("#hidReserveKeyId").val() || $("#propertyinfo").attr("tkeyid");
    item.PropertyKeyId = $("#propertyinfo").attr("pkeyid");
    item.AttachmentName = $("#txtAttachmentName").val();
    item.AttachmentPath = $("#txtAttachmentPath").val();
    item.Content = content;
    item.MsgUserKeyIds = contactsKeyIds;
    item.MsgDeptKeyIds = contactsDepartKeyIds;

    item.MsgTime = msgtime;
    $.ajax({
        url: "inquiry-take-see-follow-add-ajax",
        type: "POST",
        data: JSON.stringify(item),
        success: function (data) {
            if (data != "ok") {
                var msg = data.replace("#error:#", "");
                $.OKDialogAgency('<div class="tc">' + msg + '</div>');
            } else {
                if (window.location.href.indexOf("inquiry-detail-follow") > -1) {
                    $("#searchForm").submit();
                    art.dialog({ id: "saveInputGuide" }).close();
                    window.location = window.location;
                } else {
                    window.location = window.location;
                }
            }
        },
        error: function (e) {
            $.OKDialogAgency('<div class="tc">' + e + '</div>');
        }
    });
    $("#saveTakeCheck").removeAttr("disabled");
};

//验证
var VerifySaveTakeCheckClick = function () {
    agencyVerify.notNullInput(".aui_content", ".aui_content #txtContent", true, "blur");
    $(".aui_content #txtContent").blur();

    if ($(".aui_content .wrong").length > 0) {
        return false;
    }
    else {
        return true;
    }
}
takeSee.saveTakeCheck = function () {
    $("#saveTakeCheck").attr("disabled", "disabled");
    if (VerifySaveTakeCheckClick()) {
        if ($("#hidReserveKeyId").val() || $("#propertyinfo").html()) {
        } else {
            $.OKDialogAgency('<div class="tc">必须选择一个约看或者房源！</div>');
            $("#saveTakeCheck").removeAttr("disabled");
            return;
        }
        if ($("#txtEmployeeName").val() != "" && $("#hidUserId").val() == "") {
            $.OKDialogAgency('<div class="tc">陪看人必须从下拉菜单中选择！</div>');
            $("#saveTakeCheck").removeAttr("disabled");
            return;
        }

        if ($.trim($("#txtContent").val()) == "") {
            $("#txtContent").parent().find(".wrong").show();
            $("#saveTakeCheck").removeAttr("disabled");
            return;
        }

        $.dialog({
            id: "saveInputGuide",
            lock: true,
            content: $("#saveInputGuide").html(),
            close: function () {
                $('#saveTakeCheck').removeAttr('disabled');
            }
        });
    }
};
takeSee.selectTakingForEdit = function (e) {
    var currentel = $(e);
    var temp = currentel.attr("PropertyInfo");
    switch (currentel.attr("TrustType")) {
        case "出售":
            temp += "    交易类型：<span name='trusttype'>出售</span>";
            temp += "    售价：<span name='saleprice'>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
            $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option>");
            $("#salePriceSpan").show();
            $("#rentPriceSpan").hide();
            break;
        case "出租":
            temp += "    交易类型：<span name='trusttype'>出租</span>";
            temp += "    租价：<span name='rentprice'>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
            $("#cmbSeePropertyType").html("<option value='10' selected='selected'>看租</option>");
            $("#salePriceSpan").hide();
            $("#rentPriceSpan").show();
            break;
        case "租售":
            temp += "    交易类型：<span name='trusttype'>租售</span>";
            temp += "    售价：<span name='saleprice'>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
            temp += "    租价：<span name='rentprice'>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
            if (currentel.attr("SeePropertyType") == "看售") {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            } else if (currentel.attr("SeePropertyType") == "看租") {
                $("#cmbSeePropertyType").html("<option value='20'>看售</option><option value='10' selected='selected'>看租</option>");
                $("#salePriceSpan").hide();
                $("#rentPriceSpan").show();
            } else {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            }
            break;
        default:
            temp += "    交易类型：<span name='trusttype'>无效</span>";
            temp += "    售价：<span name='saleprice'>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
            temp += "    租价：<span name='rentprice'>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
            if (currentel.attr("SeePropertyType") == "看售") {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            } else if (currentel.attr("SeePropertyType") == "看租") {
                $("#cmbSeePropertyType").html("<option value='20'>看售</option><option value='10' selected='selected'>看租</option>");
                $("#salePriceSpan").hide();
                $("#rentPriceSpan").show();
            } else {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            }
            break;
    }
    $("#propertyinfo").attr("pkeyid", "");
    $("#propertyinfo").attr("tkeyid", currentel.attr("takingid"));
    $("#propertyinfo").html(temp);
    if (currentel.attr("RentPrice")) {
        $("#txtRentPrice").attr("value", currentel.attr("RentPrice"));
    } else {
        $("#txtRentPrice").attr("value", "");
    }
    if (currentel.attr("SalePrice")) {
        $("#txtSalePrice").attr("value", currentel.attr("SalePrice"));
    } else {
        $("#txtSalePrice").attr("value", "");
    }
    $("#takingseeTable").hide();
};
takeSee.selectPerportyForEdit = function (e) {
    var currentel = $(e);
    var trustTypeCode = currentel.attr("TrustTypeCode");
    var temp = currentel.attr("PropertyInfo");
    switch (trustTypeCode) {
        case "10":
            temp += "    交易类型：<span name='trusttype'>出租</span>";
            temp += "    租价：<span name='rentprice'>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
            $("#cmbSeePropertyType").html("<option value='10' selected='selected'>看租</option>");
            $("#salePriceSpan").hide();
            $("#rentPriceSpan").show();
            break;
        case "20":
            temp += "    交易类型：<span name='trusttype'>出售</span>";
            temp += "    售价：<span name='saleprice'>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
            $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option>");
            $("#salePriceSpan").show();
            $("#rentPriceSpan").hide();
            break;
        case "30":
            temp += "    交易类型：<span name='trusttype'>租售</span>";
            temp += "    售价：<span name='saleprice'>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
            temp += "    租价：<span name='rentprice'>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
            if (currentel.attr("SeePropertyType") == "看售") {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            } else if (currentel.attr("SeePropertyType") == "看租") {
                $("#cmbSeePropertyType").html("<option value='20'>看售</option><option value='10' selected='selected'>看租</option>");
                $("#salePriceSpan").hide();
                $("#rentPriceSpan").show();
            } else {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            }
            break;
        default:
            temp += "    交易类型：<span name='trusttype'>无效</span>";
            temp += "    售价：<span name='saleprice'>" + (currentel.attr("SalePrice") ? currentel.attr("SalePrice") : "") + "万</span>";
            temp += "    租价：<span name='rentprice'>" + (currentel.attr("RentPrice") ? currentel.attr("RentPrice") : "") + "元</span>";
            if (currentel.attr("SeePropertyType") == "看售") {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            } else if (currentel.attr("SeePropertyType") == "看租") {
                $("#cmbSeePropertyType").html("<option value='20'>看售</option><option value='10' selected='selected'>看租</option>");
                $("#salePriceSpan").hide();
                $("#rentPriceSpan").show();
            } else {
                $("#cmbSeePropertyType").html("<option value='20' selected='selected'>看售</option><option value='10'>看租</option>");
                $("#salePriceSpan").show();
                $("#rentPriceSpan").hide();
            }
            break;
    }
    $("#propertyinfo").attr("pkeyid", currentel.attr("keyid"));
    $("#propertyinfo").attr("tkeyid", "");
    $("#propertyinfo").html(temp);
    if (currentel.attr("RentPrice")) {
        $("#txtRentPrice").attr("value", currentel.attr("RentPrice"));
    } else {
        $("#txtRentPrice").attr("value", "");
    }
    if (currentel.attr("SalePrice")) {
        $("#txtSalePrice").attr("value", currentel.attr("SalePrice"));
    } else {
        $("#txtSalePrice").attr("value", "");
    }
    art.dialog({ id: 'selectSource' }).close();
};
takeSee.saveOtherFollow = function (e, index, itemcode) {
    $("#btnPrivatePublicModelSubmit,#btnPublicContentModel").attr("disabled", "disabled");
    if (!$(e).parent().parent().find("textarea").val()) {
        $(e).parent().parent().find(".wrong").show();
        $("#btnPrivatePublicModelSubmit,#btnPublicContentModel").removeAttr("disabled");
        return;
    }

    var url = window.location.href;
    if (url.indexOf("inquiryCategory=2") >= 0) {
        if ($.trim($("#txtPublicContentModel").val()) == "") {
            $("#txtPublicContentModel").parent().find(".wrong").show();
            $("#btnPublicContentModel").removeAttr("disabled");
            return;
        }
    } else {
        if ($.trim($("#txtContentModel").val()) == "") {
            $("#txtContentModel").parent().find(".wrong").show();
            $("#btnPrivatePublicModelSubmit").removeAttr("disabled");
            return;
        }
    }

    //提醒Ta
    var contactsKeyIds = [], customerOrDeptNames = [], contactsDepartKeyIds = [];
    var content = $(e).parent().parent().find("textarea").val();
    var msgtime = $("#txtMsgTime2").val();

    if (!!$("#spanAddContacts3") && $("#spanAddContacts3").find("span").length > 0) {
        $("#spanAddContacts3").find("span").each(function () {
            var contactsKeyId = $(this).find("[name=contactsKeyId]").val();
            var contactsName = $(this).find("[name=contactsName]").val();

            var contactsDepKeyId = $(this).find("[name=contactsDepKeyId]").val();
            var contactsDepartKeyId = $(this).find("[name=contactsDepartKeyId]").val();
            var contactsDepartName = $(this).find("[name=contactsDepartName]").val();
            if (contactsKeyId) {
                contactsKeyIds.push(contactsKeyId);
            }
            if (contactsName) {
                customerOrDeptNames.push(contactsName);
            }

            if (contactsDepartKeyId) {
                contactsDepartKeyIds.push(contactsDepartKeyId);
            }
            if (contactsDepartName) {
                customerOrDeptNames.push(contactsDepartName);
            }
        });
    }
    if (customerOrDeptNames.length > 0) {
        content = $(e).parent().parent().find("textarea").val() + ";提示Ta:" + customerOrDeptNames.join(",");
    }

    var reqData = { "InquiryKeyId": $("#hidckid").val(), "Content": content, "FollowTypeKeyId": index, "MsgTime": msgtime };
    if (contactsKeyIds.length > 0) {
        reqData.MsgUserKeyIds = contactsKeyIds.join(",");
    }
    if (contactsDepartKeyIds.length > 0) {
        reqData.MsgDeptKeyIds = contactsDepartKeyIds.join(",");
    }

    $.AjaxAgency("/customer/inquiry-other-follow-add-ajax", reqData, function (data) {
        if (data != "ok") {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
            $("#btnPrivatePublicModelSubmit,#btnPublicContentModel").removeAttr("disabled");
        } else {
            if (window.location.href.indexOf("details")) {
                $.OKDialogAgency('<div class="tc">提交成功！</div>', '提示', function () {
                    if (itemcode) {
                        window.parent.location.reload();
                    } else {
                        $("#searchForm").submit();
                        takeSee.clearInput();
                        $("#spanAddContacts3").empty();
                    }
                    $("#btnPrivatePublicModelSubmit,#btnPublicContentModel").removeAttr("disabled");
                });
            }
        }
    });
};

takeSee.DepartmentUrl = function () {
    return "/property/department-auto-match-ajax?name=" + escape($('#txtDepartmentName').val()) + '&hasPublicAccount=true&scope=3';
};
takeSee.UserUrl = function () {
    return "/property/user-auto-match-ajax?dname=" + escape($('#txtDepartmentName').val()) + "&pname=" + escape($('#txtEmployeeName').val()) + '&hasPublicAccount=true&scope=3';
};
takeSee.EstateUrl = function () {
    var estateName = $('#txtEstateNames').val().split('+');
    return "/estate/AutoEstate?EstateName=" + escape(estateName[estateName.length - 1]);
};
//初始化build的属性或方法Start  
takeSee.getbuildUrl = function () {
    return '/property/building-for-estate-obatin-ajax?EstateName=' + escape($("#txtEstateNames").val()) + '&BuildName=' + $("#txtBuildingNames").val();
};
//根据楼盘名获得栋座单元
takeSee.getBuildingByEstate = function (ele, txtEstateId) {
    var tempEstateValue = $('#' + txtEstateId).val();
    var tempEstateElement = $('#' + txtEstateId);
    var reg = /[+]/g;
    if (!tempEstateValue || reg.test(tempEstateValue) || tempEstateElement.attr('isexistbuild') == 'false') {
        $("#txtBuildingNames").val("");
        $("#hidBuilding2").css('display', 'none');
        $("#hidBuilding2 ul").html("");
        return false;
    }

    var reqData = {
        'EstateName': tempEstateValue
    };
    $.AjaxAgency('/property/building-for-estate-obatin-ajax', reqData, function (data) {
        if (data) {
            tempEstateElement.attr('isexistbuild', 'false');
            multipleBuildingCheckBox('#txtBuildingNames', 'hidBuilding2', data, []);
        }
    });
};

//选择房源按纽
takeSee.selectPerportDiv = function (selector, isSingleChoose, returnFun) {
    $(selector).bind("click", function () {
        $.dialog({
            id: "selectSource",
            title: "选择房源",
            lock: true,
            width: 730,
            content: $("#selectSource").html()
        });
        agencyVerify.zhengFuIntInput('#txtFloor', false);
        //房型数据加载
        multipleCheckBox('#txtPropertyType', 'propertyType', dataBind.getRealDataByType(25), [], 2, '');
        if (isSingleChoose) {
            $('#selectSource').find("#btnCheckdown").attr('showAndHid', '1');
        } else {
            $('#selectSource').find("#btnCheckdown").removeAttr('showAndHid');
        }
        $("#btnCheckdown").hide();
        $("#txtEstateNames").autocomplete(takeSee.EstateUrl, {
            width: 260,
            max: 1000,
            Default: 1,
            selectFirst: false,
            cacheLength: 0,
            multiple: true,
            multipleSeparator: '+',
            formatItem: function (row) {
                return row.EstateFullName;
            },
            formatResult: function (row) {
                return row.EstateName;
            }
        }).result(function (a, b) {
            $("#txtEstateNames").attr('isexistbuild', 'true');
            $("#txtHouseNo").removeAttr("readonly");
            $("#txtBuildingNames").removeAttr("readonly");
        });

        $('#txtEstateNames').unbind('change').bind('change', function () {
            $('#txtBuildingNames').val('');
            $('#hidBuilding2 ul').html('');
            $(this).attr('isexistbuild', 'true');
            if ($(this).val() == "") {
                $("#txtHouseNo").attr("readonly", "readonly").val("");
                $("#txtBuildingNames").attr("readonly", "readonly").val("");
            }
            else //楼盘 栋座 模糊查询 lixn 2016-04-21
            {
                $("#txtBuildingNames").removeAttr("readonly");
                $("#txtHouseNo").removeAttr("readonly");
            }
        });


        //栋座自动完成及赋值隐藏域
        $("#txtBuildingNames").autocomplete(takeSee.getbuildUrl, {
            width: 260,
            max: 1000,
            Default: 1,
            selectFirst: false,
            cacheLength: 0,
            multiple: true,
            clickMode: true,
            minChars: 0,
            formatItem: function (row) {
                return row.BuildingName;
            },
            formatResult: function (row) {

                return row.BuildingName;
            }
        }).result(function (a, b) {
            $("#hidBuildKeyId").val(b.KeyId);
        });

       

    });
    
};

takeSee.AppendShowTakeSeeListClickEvent = function () {
    $('#takeSeeListImg').css('display', 'block');
    return false;
};

takeSee.AppendHideTakeSeeListClickEvent = function () {
    $('#takeSeeListImg').css('display', 'none');
};

takeSee.AppendDelTakeSeeListClickEvent = function () {
    $('#uploadTakeSeeListDiv').html('');
    $('#takeSeeListImg').html('');
    $('#txtAttachmentName').val('');
    $('#txtAttachmentPath').val('');
};

takeSee.searchBefor = function () {
    $("#hidradom").val(Math.random());
    other.showLoaderMask();
};

takeSee.selectPerportDiv1 = function (selector, isSingleChoose, returnFun, trustid,tel) {
    $(selector).bind("click", function () {
        $("#hid_trustid").val(trustid);
        $("#hid_trusttel").val(tel);
        $.dialog({
            id: "selectSource",
            title: "选择房源",
            lock: true,
            width: 730,
            content: $("#selectSource").html()
        });
        //房型数据加载
        multipleCheckBox('#txtPropertyType', 'propertyType', dataBind.getRealDataByType(25), [], 2, '');
        if (isSingleChoose) {
            $('#selectSource').find("#btnCheckdown").attr('showAndHid', '1');
        } else {
            $('#selectSource').find("#btnCheckdown").removeAttr('showAndHid');
        }
        $("#btnCheckdown").hide();
        $("#txtEstateNames").autocomplete(takeSee.EstateUrl, {
            width: 260,
            max: 1000,
            Default: 1,
            selectFirst: false,
            cacheLength: 0,
            multiple: true,
            multipleSeparator: '+',
            formatItem: function (row) {
                return row.EstateFullName;
            },
            formatResult: function (row) {
                return row.EstateName;
            }
        }).result(function (a, b) {
            $("#txtEstateNames").attr('isexistbuild', 'true');
            $("#txtHouseNo").removeAttr("readonly");
            $("#txtBuildingNames").removeAttr("readonly");
        });

        $('#txtEstateNames').unbind('change').bind('change', function () {
            $('#txtBuildingNames').val('');
            $('#hidBuilding2 ul').html('');
            $(this).attr('isexistbuild', 'true');
            if ($(this).val() == "") {
                $("#txtHouseNo").attr("readonly", "readonly").val("");
                $("#txtBuildingNames").attr("readonly", "readonly").val("");
            }
        });

        //栋座自动完成及赋值隐藏域
        $("#txtBuildingNames").autocomplete(takeSee.getbuildUrl, {
            width: 260,
            max: 1000,
            Default: 1,
            selectFirst: false,
            cacheLength: 0,
            multiple: true,
            clickMode: true,
            minChars: 0,
            formatItem: function (row) {
                return row.BuildingName;
            },
            formatResult: function (row) {

                return row.BuildingName;
            }
        }).result(function (a, b) {
            $("#hidBuildKeyId").val(b.KeyId);
        });

    });
};